<template>
  <div id="topSearch">
    <div class="search-box">
      <el-form
        :inline="true"
        :model="formInline"
        ref="ruleForm"
        class="demo-form-inline"
      >
        <el-form-item label="落地页名称" prop="landingPageId">
          <el-select
            size="small"
            v-model="formInline.landingPageId"
            placeholder="请您输入落地页名称"
            filterable
            clearable
          >
            <el-option
              v-for="item in pageNameList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="发布状态" prop="status">
          <el-select size="small" v-model="formInline.status" clearable>
            <el-option
              v-for="item in statusList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="时间" prop="createTime">
          <el-date-picker
            size="small"
            v-model="formInline.createTime"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button type="success" icon="el-icon-search" @click="toSearch">
            查询
          </el-button>
          <el-button type="success" plain @click="resetForm('ruleForm')">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
import { landingPageName } from '@/api/activityCenter/landingPage'
export default {
  data() {
    return {
      formInline: {
        landingPageId: '',
        status: '',
        startTime: '',
        endTime: '',
        createTime: []
      },
      pageNameList: [],
      statusList: []
    }
  },
  watch: {
    'formInline.createTime': {
      handler(val) {
        this.formInline.startTime = val && val.length ? val[0] : ''
        this.formInline.endTime = val && val.length ? val[1] : ''
      },
      deep: true
    }
  },
  async mounted() {
    this.statusList = await sysNormalDisable('landing_page_status')
    landingPageName({}, (res) => {
      this.pageNameList = res
    })
  },
  methods: {
    toSearch() {
      const obj = Object.assign({}, this.formInline)
      delete obj.createTime
      this.$emit('toSearch', obj)
    },
    resetForm(formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>
<style lang="less" scoped></style>
